package com.hardydou.pattern.singleton;


import java.util.concurrent.atomic.AtomicInteger;

/**
 * 单例模式
 * <p>
 * 静态内部类
 *
 * @author hardy
 */
public class StaticClazzSingleton {

    private static AtomicInteger count = new AtomicInteger(0);
    private static boolean initOk = false;

    private static class NoThing {
        private static StaticClazzSingleton instance = new StaticClazzSingleton();
    }


    private StaticClazzSingleton() {
        count.getAndIncrement();
        try {
            Thread.sleep(500L);
        } catch (Exception e) {

        }
        initOk = true;
    }


    public static StaticClazzSingleton getInstance() {
        return NoThing.instance;
    }


    /**
     * 测试用
     *
     * @return
     */
    public static int getCount() {
        return count.get();
    }

    public static boolean hasInit() {
        return initOk;
    }


}
